package com.xinzhi.savingpot.userinfo.service.impl;

import com.xinzhi.savingpot.userinfo.mapper.IChasePasswordMapper;
import com.xinzhi.savingpot.userinfo.service.UpdatePasswordService;
import com.xinzhi.savingpot.util.BaseResponse;
import com.xinzhi.savingpot.util.IsMobileUtil;
import com.xinzhi.savingpot.util.MD5Util;
import com.xinzhi.savingpot.util.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UpdatePasswordServiceImpl implements UpdatePasswordService {
    @Autowired
    private IChasePasswordMapper iChasePasswordMapper;
    @Autowired
    private IsMobileUtil isMobileUtil;
    @Autowired
    private RedisUtil redisUtil;

    @Override
    public BaseResponse chaseps(String phone,String password,String code) {

        if (isMobileUtil.checkCellphone(phone)) {
            String oldCode = (String) redisUtil.get(phone);
            if (code.equals(oldCode)) {
                int chase = iChasePasswordMapper.chase(phone, MD5Util.stringMD5(password));
                if (chase > 0) {
                    return new BaseResponse(200, "修改密码成功");
                }
                return new BaseResponse(200, "修改密码失败");
            }
            return new BaseResponse(100, "请输入正确的验证码");
        }
        return new BaseResponse(100, "请输入正确的手机号密码");
    }
    }
